package com.childenglish.utils;

public class R<T> {
    private int code;
    private String message;
    private T data;

    // 成功静态方法
    public static <T> R<T> ok() {
        return ok("成功");
    }

    public static <T> R<T> ok(String message) {
        R<T> r = new R<>();
        r.setCode(200);
        r.setMessage(message);
        return r;
    }

    // 错误静态方法
    public static <T> R<T> error() {
        return error("失败");
    }

    public static <T> R<T> error(String message) {
        R<T> r = new R<>();
        r.setCode(500);
        r.setMessage(message);
        return r;
    }

    // 设置数据方法
    public R<T> data(T data) {
        this.setData(data);
        return this;
    }

    // getter setter
    public int getCode() { return code; }
    public void setCode(int code) { this.code = code; }

    public String getMessage() { return message; }
    public void setMessage(String message) { this.message = message; }

    public T getData() { return data; }
    public void setData(T data) { this.data = data; }
}